Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly encode structs without members #1968

Merged

Conversation

Supertuba12
Copy link
Contributor

The JSON RPC API specification for 'eth_signTypedData_v4' does not explicitly state that the required struct 'EIP712Domain' has to define any members [1]. The current implementation cannot correctly encode such a structure, as it assumes that at least one member has been parsed and added to the struct's string representation.

[1] https://eips.ethereum.org/EIPS/eip-712#specification-of-the-eth_signtypeddata-json-rpc

What does this PR do?

This commit refactors the struct encoding function such that it now accepts structures that does not define any members. This PR aims to resolve issue #1967.

Where should the reviewer start?

There's only one function changed. I've also gone ahead and added a new test.

Why is it needed?

This is needed to fully support the EIP-712 specification. Without it, web3j fails to properly handle valid types of structured data.

The JSON RPC API specification for 'eth_signTypedData_v4' does not
explicitly state that the required struct 'EIP712Domain' has to define
any members [1]. The current implementation cannot correctly encode
such a structure, as it assumes that at least one member has been
parsed and added to the struct's string representation.

This commit refactors the struct encoding function such that it now
accepts structures that does not define any members.

[1] https://eips.ethereum.org/EIPS/eip-712#specification-of-the-eth_signtypeddata-json-rpc
@codecov
Copy link

codecov bot commented Oct 4, 2023

Codecov Report

Merging #1968 (d349a79) into master (ac0618c) will decrease coverage by 0.03%.
Report is 2 commits behind head on master.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##             master    #1968      +/-   ##
============================================
- Coverage     68.49%   68.46%   -0.03%     
+ Complexity     3004     3003       -1     
============================================
  Files           488      488              
  Lines         12559    12556       -3     
  Branches       1637     1637              
============================================
- Hits           8602     8597       -5     
- Misses         3482     3483       +1     
- Partials        475      476       +1     
Files Coverage Δ
...n/java/org/web3j/crypto/StructuredDataEncoder.java 89.65% <100.00%> (-0.12%) ⬇️

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@NickSneo NickSneo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@NickSneo NickSneo merged commit 2944092 into hyperledger-web3j:master Oct 4, 2023
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants